/**
 * @author Voislav Jovanovic <voislavj@gmail.com>
 * @name Main Javascript
 */
 
// initialization (onload)
$(function(){
	setFooterPosition();
	setMainWidth();
	$(window).resize(function(){
		$(".menu.left").height($("body").height());
		setFooterPosition();
		setMainWidth();
	});
	
	bodyBackground();
	$(window).resize(bodyBackground);
	
	$('.submenu').click(function(){
		var ul = $(this).children('ul');
		var speed = 300;
		var ease = "easeOutExpo";
		if(ul.attr("animation")==1){
			return;
		}
		if(ul.is(":visible")){
			$(this).removeClass("hover");
			ul.attr("animation", 1);
			ul.fadeOut(speed, ease, function(){
				ul.attr("animation", 0);
			});
		}else{
			$(this).addClass("hover");
			ul.attr("animation", 1);
			ul.fadeIn(speed, ease, function(){
				ul.attr("animation", 0);
			});
		}
	})
});

function bodyBackground(){
	var b = $(document.body);
	var h = Math.round(b.height()*0.5);
	b.css("background-image", "url(../image/image.php?img=krsto-milovanovic.png&h="+h+")");
}
function setMainWidth(){
	$(".main").width($(document.body).width() - $(".menu").width() - parseInt($(".main").css("padding-left")))
}
function setFooterPosition(){
	var footer = $(".footer");
	var mt = $("body").height()-footer.height();
	var mb = parseInt(footer.css("margin-bottom"));
	
	var tmp = $(document.body).height() - mt - footer.height();
	if(tmp < mb){
		mt = mt - (mb-tmp);
	}

	footer.css("margin-top",  mt);
	$(".footnote").css("top", mt);
}